{layout name="layout/header" /}
<link href="root/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="root/css/plugins/datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet">
<link href="root/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
<link href="root/css/plugins/summernote/summernote.css" rel="stylesheet">
<link href="root/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
<link href="root/css/plugins/switchery/switchery.css" rel="stylesheet">
<script src="root/js/plugins/switchery/switchery.js"></script>
<div class="wrapper wrapper-content animated fadeInRight" id="app">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5><a href="{:url('vote/index')}">活动列表</a>/<a href="{:url('index',['vote_id'=>$vote.id])}"> {$vote.name} </a>/ {$title}</h5>
                </div>
                <div class="ibox-content">
                    <p>
                        <a type="button" class="btn btn-primary btn-outline" href="{:url('index',['vote_id'=>$vote.id])}">返回列表</a>
                    </p>
                </div>
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" id="form">
                        <div class="form-group">
                            <label class="col-sm-1 control-label">参赛名称</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="name" name="name"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">参赛编号</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="mid" name="mid"/>
                                <span class="help-block m-b-none">可以不填，暂时未启用该字段，如果填入只能填入数字</span>
                            </div>
                        </div>
                        <div class="form-group" v-if="vote.type_enable == 1">
                            <label class="col-sm-1 control-label">分类</label>
                            <div class="col-sm-11">
                                <select class="form-control m-b" v-model="vote_type_id" name="vote_type_id">
                                    <option value="0">请选择</option>
                                    <option :value="i.id" v-for="i in type">{{i.name}}</option>
                                </select>
                            </div>
                        </div>
<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-1 control-label">首页简介</label>-->
<!--                            <div class="col-sm-11">-->
<!--                                <input type="text" class="form-control" v-model="description" name="description"/>-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="form-group" >
                            <label class="col-sm-1 control-label">封面图片</label>
                            <div class="col-sm-11">
                                <button class="btn btn-success product_upload_img" type="button">
                                    <i class="fa fa-upload"></i>&nbsp;&nbsp;<span class="bold">上传</span>
                                </button>
                                <input class="vue_img" type="file" style="display: none;" data-field="head_img"/>
                            </div>
                            <div class="col-sm-11 col-sm-offset-1 ">
                                <div class="row" id="imgs" v-if="head_img!=''">
                                    <div class="img_box col-xs-12 col-md-3" >
                                        <a class="fancybox" :href="head_img">
                                            <img alt="image" :src="head_img"/>
                                        </a>
                                        <a class="glyphicon glyphicon-trash" onclick="del_wx_img(this,'head_img');" :data-value="head_img"></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">详情页默认显示</label>
                            <div class="col-sm-10">
                                <div class="radio i-checks">
                                    <label><input type="radio" v-model="info_pick" value="1" name="info_pick"> <i></i>视频</label>
                                    <label><input type="radio" v-model="info_pick" value="2" name="info_pick"> <i></i>图片</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-sm-1 control-label">视频链接</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="video_url" name="video_url"/>
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-sm-1 control-label">详情页图片</label>
                            <div class="col-sm-11">
                                <button class="btn btn-success product_upload_img" type="button">
                                    <i class="fa fa-upload"></i>&nbsp;&nbsp;<span class="bold">上传</span>
                                </button>
                                <input class="vue_img" type="file" style="display: none;" data-field="img"/>
                            </div>
                            <div class="col-sm-11 col-sm-offset-1 ">
                                <div class="row" id="img" v-if="img!=''">
                                    <div class="img_box col-xs-12 col-md-3" >
                                        <a class="fancybox" :href="img">
                                            <img alt="image" :src="img"/>
                                        </a>
                                        <a class="glyphicon glyphicon-trash" onclick="del_wx_img(this,'img');" :data-value="img"></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">显示</label>
                            <div class="col-sm-10">
                                <div class="radio i-checks">
                                    <label><input type="radio" v-model="display" value="1" name="display"> <i></i>显示</label>
                                    <label><input type="radio" v-model="display" value="0" name="display"> <i></i>隐藏</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">投票状态</label>
                            <div class="col-sm-10">
                                <div class="radio i-checks">
                                    <label><input type="radio" v-model="enable" value="1" name="enable"> <i></i>是</label>
                                    <label><input type="radio" v-model="enable" value="0" name="enable"> <i></i>否</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">排序</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="sort" name="sort">
                                <span class="help-block m-b-none">数字越大，排序越靠前</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">备注</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="remark" name="remark">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">详情页介绍</label>
                            <div class="col-sm-11">
                                <textarea class="form-control" style="display: none" v-model="info" name="info"></textarea>
                                <div class="ibox-content no-padding" >
                                    <div class="summernote" v-html="info" data-field="info">

                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <a class="btn btn-primary" @click="submit" type="submit">保存内容</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- iCheck -->
<script src="root/js/plugins/iCheck/icheck.min.js"></script>
<!--layer-->
<script src="root/js/plugins/layer/layer.min.js"></script>
<script src="root/js/plugins/datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="root/js/plugins/datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="root/js/plugins/validate/jquery.validate.min.js"></script>
<script src="root/js/plugins/validate/messages_zh.min.js"></script>

<script src="root/js/plugins/summernote/summernote.min.js"></script>
<script src="root/js/plugins/summernote/summernote-zh-CN.js"></script>
<script src="root/js/plugins/fancybox/jquery.fancybox.js"></script>

<script>
    var vote_id = {$vote.id};
    var data = {$data};
    var url = "{$url}";
    if(data==1){
        data = {
            id:0,
            vote_id:vote_id,
            vote_type_id:0,
            name:'',
            mid:'',
            info:'',
            description:'',
            head_img:'',
            remark:'',
            img:'',
            video_url:'',
            info_pick:2,
            enable:1,
            sort:0,
            display:1,
        }
    }
    //投票的分类
    data.type = {$vote_type};
    data.vote = {
        type_enable :"{$vote.type_enable}"
    };
    new Vue({
        el:"#app",
        data:data,
        methods:{
            submit:function () {
                $("#form").validate({
                    rules:{
                        name:{
                            required:true,
                        },
                        mid:{
                            // required:true,
                            digits:true,
                        },
                    },
                    messages:{
                        vote_type:{
                            min:'请选择分类'
                        },
                        mid:{
                            // digits:''
                        }
                    }
                })
                if($("#form").valid()) {
                    if(data.head_img == ''){
                        layer.msg('封面图片不能为空')
                        return ;
                    }
                    if(data.info_pick == 1 && data.video_url == ''){
                        layer.msg('视频链接不能为空')
                        return ;
                    }
                    if(data.info_pick == 2 && data.img == ''){
                        layer.msg('详情页图片不能为空')
                        return ;
                    }
                    $.post(url,data,function (res) {
                        layer.msg(res.msg);

                        if(res.code==1){
                            setTimeout(function () {
                                window.location.href= "{:url('index',['vote_id'=>$vote.id])}"
                            },1500)
                        }
                    },'json')
                }

            }
        },
        mounted:function () {
            checks();

            $('.fancybox').fancybox({
                openEffect: 'none',
                closeEffect: 'none'
            });
            $('.summernote').summernote({
                lang:'zh-CN',
                disableDragAndDrop: true,
                // 重写图片上传
                onImageUpload: function(files, editor, $editable) {
                    sendFile(files[0],editor,$editable);
                },
                onblur:function () {
                    var field = $(this).parent().prev().attr('data-field')
                    data[field] = $(this).code();
                }
            });
        }
    });
</script>

<script>
    $('input[name="enable"]').on('ifChecked', function(event){
        data.enable = $(this).val()
    });
    $('input[name="display"]').on('ifChecked', function(event){
        data.display = $(this).val()
    });
    $('input[name="info_pick"]').on('ifChecked', function(event){
        data.info_pick = $(this).val()
    });

</script>
